#! /usr/bin/env python
#coding:utf8

import MySQLdb
import xlrd

wb = xlrd.open_workbook("cgf_firtfight.xls")
sheet = wb.sheet_by_index(0)
nrows = sheet.nrows  #行数  
ncols = sheet.ncols  #列数 

dfun=[]
for i in range(1,nrows):  
    dfun.append(sheet.row_values(i))  

val=''  
for i in range(0,ncols):  
    val += '%s'  
    if  i < (ncols - 1):
        val += ','
query = 'insert into cgf_firtfight values(' + val + ')'
print query  
# insert into simple values(%s,%s,%s,%s)

con = MySQLdb.connect('127.0.0.1', 'root', '123456', 'xxjt', charset='utf8');
cur = con.cursor()
cur.executemany(query,dfun)
con.commit()
cur.close()
con.close()

#  python脚本实现excel和mysql数据库表的导入导出
# http://blog.csdn.net/christ_shl/article/details/48680269